package com.zz.man.aspect;


import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

@Aspect
@Component
public class HttpAspect {
    private final static Logger log = LoggerFactory.getLogger(HttpAspect.class);

    @Pointcut("execution(public * com.zz.man.controller.GirlController.*(..))")
    public void log(){

    }
    @Before("log()")
    public void dobefore(JoinPoint joinPoint){
        ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = servletRequestAttributes.getRequest();
        //url
        log.info("url={}",request.getRequestURL());
        //参数
        log.info("method={}",request.getMethod());
        //method
        log.info("ip={}",request.getRemoteAddr());
        //类方法
        log.info("class_mothod={}",joinPoint.getSignature().getDeclaringTypeName()+"."+joinPoint.getSignature().getName());
        //参数
        log.info("args={}",joinPoint.getArgs());
        log.info("啦啦啦啦啦");
        System.out.println("啦啦啦啦啦");
    }
    @After("log()")
    public void doafter(){
        log.info("吼吼吼吼吼吼");
        System.out.println("吼吼吼吼吼吼");
    }

    @AfterReturning(returning = "object",pointcut = "log()")
    public void doafterRuturning(Object object){
        log.info("response={}",object.toString());
        System.out.println("返回值");
    }
}
